package com.huluobo.a2307monthdemo2.adapter

import android.animation.ObjectAnimator
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.huluobo.a2307monthdemo2.R
import com.huluobo.a2307monthdemo2.utils.ImageUtils
import com.huluobo.lib_base.bean.VideoBean
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

/**
 *  Created by LC on 2025/10/9.
 */
class MultiVideoAdapter : BaseMultiItemQuickAdapter<VideoBean, BaseViewHolder>() {
    init {
        addItemType(0, R.layout.item_videos)
        addItemType(1, R.layout.item_videos_live)
        addItemType(2, R.layout.item_videos_full)
        addItemType(5, R.layout.item_videos_full)
    }

    override fun convert(holder: BaseViewHolder, item: VideoBean) {

        val player = holder.getView<StandardGSYVideoPlayer>(R.id.item_videos_player)
        player.backButton.visibility = View.GONE
        player.setUp(item.videopath, true, "")
        val imageView = ImageView(context)
        ImageUtils.loadImage(context, item.videomainimg, imageView)
        player.thumbImageView = imageView

        if (item.address.isNullOrEmpty()) {
            holder.setText(R.id.item_videos_address_tv, "定位失败")
        } else {
            holder.setText(R.id.item_videos_address_tv, item.address)
        }
        holder.setText(R.id.item_videos_time_tv, item.publishtime)
        holder.setText(R.id.item_videos_authname_tv, item.authname)
        holder.setText(R.id.item_videos_caption_tv, item.caption)
        holder.setText(R.id.item_videos_pao_tv, "${item.authname}的原创作品")

        if (item.type != 1) {
            ImageUtils.loadICircleImage(context, item.headpath, holder.getView(R.id.item_videos_header_iv))
            if (item.guanzhu == 0) {
                holder.getView<ImageView>(R.id.item_videos_add_iv).visibility = View.VISIBLE
            } else {
                holder.getView<ImageView>(R.id.item_videos_add_iv).visibility = View.GONE
            }

            if (item.dianzan == 0) {
                holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuan)
            } else {
                holder.setImageResource(R.id.item_videos_like_iv, R.drawable.ic_xihuanred)
            }

            val musicPlayer = holder.getView<ImageView>(R.id.item_videos_music_player_iv)
            ImageUtils.loadICircleImage(context, item.headpath, musicPlayer)

            val animator = ObjectAnimator.ofFloat(musicPlayer, "Rotation", 0f, 360f)
            animator.duration = 3000
            animator.repeatCount = -1
            animator.interpolator = LinearInterpolator()
            animator.start()
        }
    }
}